package com.czh.controller;

import com.czh.domain.ResponseResult;
import com.czh.domain.entity.Menu;
import com.czh.domain.vo.MenuAuthorityVo;
import com.czh.domain.vo.MenuOldVo;
import com.czh.domain.vo.MenuPageVo;
import com.czh.domain.vo.MenuTreeVo;
import com.czh.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单管理控制器
 */
@RestController
@RequestMapping("system/menu")
public class MenuManageController {
    @Autowired
    private MenuService menuService;
    /**
     *    新增角色时展示菜单树
     */
    @GetMapping("/treeselect")
    public ResponseResult<List<MenuTreeVo>> getMenuTree(){
        return menuService.getRoleMenuTree();
    }
    /**
     *   编辑角色时展示对应菜单树
     */
    @GetMapping("/roleMenuTreeselect/{id}")
    public ResponseResult<MenuAuthorityVo> getMenuTreeById(@PathVariable("id") Long id){
        return menuService.getMenuTreeById(id);
    }

    /**
     *菜单管理列表展示
     */
    @GetMapping("/list")
    public ResponseResult<List<MenuPageVo>> getMenuList( String status,String menuName){
        return menuService.getMenuList(status,menuName);
    }
    @PostMapping
    public ResponseResult<Object> addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }
    @DeleteMapping("/{menuId}")
    public ResponseResult<Object> deleteMenu(@PathVariable("menuId") Long menuId){
        return menuService.deleteMenu(menuId);
    }
    @GetMapping("/{id}")
    public ResponseResult<MenuOldVo> getMenuById(@PathVariable("id") Long id){
        return menuService.getMenuById(id);
    }
    @PutMapping
    public ResponseResult<Object> updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }
}
